import datetime, time, random

item_names = [
    "book",
    "lunch",
    "taxi",
    "shopping",
    "tax fee",
    "hotel",
    "water",
    "electronic",
    "gift",
    "food",
    "game",
    "cloth",
    "houseing fee",
    "mobile phone charge",
    ]

def gentally(category_max, location_max):
    now = time.time()
    lastyear = now - 365*24*3600
    tick = []
    for i in range(100):
        tick.append(random.random() * (now - lastyear) + lastyear)
    tick.sort()
    index = 0
    for i in tick:
        date_time = datetime.datetime.fromtimestamp(int(i)).isoformat(' ')
        category_id = random.randint(1, category_max)
        location_id = random.randint(1, location_max)
        d = random.randint(0, 100)
        d2 = random.randint(0, 100)
        d3 = random.randint(0, 100)
        costCent = d*d*d+d2*d2+d3
        costName = random.choice(item_names)
        index += 1
        print "INSERT INTO \"tb_tally\" VALUES(" + str(index) + ",'" + costName + "'," + str(costCent) + "," + str(category_id) + "," + str(location_id) + ",'" + date_time + "');"

location_names = [
    "kfc",
    "home",
    "taxi",
    "shopping",
    "hotel",
    "water",
    "electronic",
    "gift",
    "food",
    "game",
    "cloth",
    ]

def gen_location(location_max):
    for i in range(location_max):
        location_name = random.choice(location_names)
        latitude = random.randrange(10 * 1000000, 50 * 1000000) * 0.000001
        longitude = random.randrange(-130 * 1000000, -100 * 1000000) * 0.000001
        print "INSERT INTO \"tb_location\" VALUES(" + str(i + 1) + ",'" + location_name + "'," + str(latitude) + "," + str(longitude) + ");"

def gen_category(category_max):
    for i in range(category_max):
        category_name = random.choice(item_names) + ' ' + random.choice(location_names)
        print "INSERT INTO \"tb_category\" VALUES(" + str(i + 1) + ",'" + category_name + "');"

category_max = 10
location_max = 20
gen_category(category_max)
gen_location(location_max)
gentally(category_max, location_max)
